package com.ruoyi.tzzl.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.tzzl.domain.WzArticle;
import com.ruoyi.tzzl.mapper.WzArticleMapper;
import com.ruoyi.tzzl.service.IWzArticleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 文章管理Service业务层处理
 *
 * @author by caoyong
 * @date 2022/11/17
 **/
@Service
public class WzArticleServiceImpl extends ServiceImpl<WzArticleMapper, WzArticle> implements IWzArticleService {


    /**
     * 查询文章管理列表
     *
     * @param wzArticle 文章管理
     * @return 文章管理集合
     */
    @Override
    public List<WzArticle> selectWzArticleList(WzArticle wzArticle) {
        LambdaQueryWrapper<WzArticle> lqw = new LambdaQueryWrapper<>();
        if (ObjectUtils.isNotEmpty(wzArticle.getArticleType())) {
            lqw.eq(WzArticle::getArticleType, wzArticle);
        }
        lqw.orderByDesc(WzArticle::getCreateTime);
        return this.list(lqw);
    }

    /**
     * 修改文章
     *
     * @param wzArticle
     */
    @Override
    public boolean update(WzArticle wzArticle) {
        WzArticle wzArticle1 = this.getById(wzArticle.getId());
        if (ObjectUtils.isNotEmpty(wzArticle.getArticleType())) {
            wzArticle1.setArticleType(wzArticle.getArticleType());
        }
        if (ObjectUtils.isNotEmpty(wzArticle.getIntroduce())) {
            wzArticle1.setIntroduce(wzArticle.getIntroduce());
        }
        if (ObjectUtils.isNotEmpty(wzArticle.getTitle())) {
            wzArticle1.setTitle(wzArticle.getTitle());
        }
        if (ObjectUtils.isNotEmpty(wzArticle.getState())) {
            wzArticle1.setState(wzArticle.getState());
        }
        return this.updateById(wzArticle1);
    }
}
